home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / lib / mathlib / psort / example / readrgb.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  2.8 KB  |  122 lines

  1. /* *****************************************************************************
  2. *
  3. * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  4. * All Rights Reserved.
  5. *
  6. * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  7. * the contents of this file may not be disclosed to third parties, copied or
  8. * duplicated in any form, in whole or in part, without the prior written
  9. * permission of Silicon Graphics, Inc.
  10. *
  11. * RESTRICTED RIGHTS LEGEND:
  12. * Use, duplication or disclosure by the Government is subject to restrictions
  13. * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  14. * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  15. * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  16. * rights reserved under the Copyright Laws of the United States.
  17. *
  18. ***************************************************************************** */
  19. /*
  20.  * ipaint - mouse images around on the screen
  21.  */
  22.  
  23. #include <stdio.h>
  24. #include <sys/types.h>
  25. #include <dirent.h>
  26. #include <gl.h>
  27. #include <gl/image.h>
  28. #include <device.h>
  29.  
  30.  
  31. unsigned short    ir[1280],    /* for reading the image file */
  32.         ig[1280],
  33.         ib[1280];
  34.  
  35. int    Haveimage;        /* we have an image file loaded */
  36.  
  37. int    x_size, y_size, n_total; /* dimensions of current image */
  38.  
  39. int    *image;        /* ptrs to pixel data areas for current image */
  40. /*
  41.  * image-file handling
  42.  *
  43.  * each available image file is described by a struct img_file.
  44.  * these structs are kept in a linked list.
  45.  */
  46.  
  47. struct img_file {
  48.     char        *name;
  49.     int        *rgb;
  50.     int        xsize, ysize;
  51. };
  52.  
  53. struct img_file *file;
  54.  
  55.  
  56. char *Progname;
  57.  
  58. extern char *malloc();
  59. extern long time();
  60. extern char *optarg;
  61. extern int optind;
  62.  
  63.  
  64. readrgb(char *filename)
  65. {
  66.     IMAGE    *image_str;
  67.     short    *c8, *c12;
  68.     int    *rgb;
  69.     int    y;
  70.     int    modesave;
  71.  
  72.     Haveimage = 0;
  73.     
  74.         image = NULL;
  75.  
  76.     if ( (image_str = iopen(filename,"r")) == NULL ) {
  77.     fprintf(stderr, "ipaint: can't open input file %s\n", filename);
  78.         system("inform 'can not open input file chosen'");
  79.         /* black_screen();  */
  80.         return;
  81.     }
  82.     if ( image_str->zsize < 3 ) {
  83.         fprintf(stderr, "ipaint: input image is not a color image %s\n",filename);
  84.         system("inform 'input image is not a color image'");
  85.         /* black_screen();  */
  86.         return;
  87.     }
  88.  
  89.     x_size = image_str->xsize;
  90.     y_size = image_str->ysize;
  91.     n_total = x_size * y_size;
  92.  
  93.     image = (int *) malloc(x_size*y_size*sizeof(int));
  94.     rgb = image;
  95.  
  96.     for (y = 0;  y < y_size;  y++) {
  97.         getrow(image_str, ir, y, 0);
  98.         getrow(image_str, ig, y, 1);
  99.         getrow(image_str, ib, y, 2);
  100.  
  101.         rgb_to_packed_rgb(ir, ig, ib, rgb, x_size);
  102.  
  103.         rgb += x_size;
  104.     }
  105.  
  106. /*    newmode(modesave);  */
  107.  
  108.     Haveimage = 1;
  109.     iclose(image_str);
  110. }  /* load file */
  111.  
  112.  
  113. rgb_to_packed_rgb(rp, gp, bp, ip, n)
  114. unsigned short *rp, *gp, *bp;
  115. int *ip;
  116. int n;
  117. {
  118.     while (n--)
  119.         *ip++ = (0<<24) | ((*bp++)<<16) | ((*gp++)<<8) | *rp++;
  120. }
  121.  
  122.